import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header

"""
解析邮箱服务器：dig proxy-in.baidu.com
v_baiguanghui@MacBook-Pro-75 101.测试脚本 % dig proxy-in.baidu.com

; <<>> DiG 9.10.6 <<>> proxy-in.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5444
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 2, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;proxy-in.baidu.com.            IN      A

;; ANSWER SECTION:
proxy-in.baidu.com.     7200    IN      CNAME   mail1-in.baidu.com.
mail1-in.baidu.com.     600     IN      CNAME   mail-in.sdns.baidu.com.
mail-in.sdns.baidu.com. 7200    IN      A       10.169.43.11
mail-in.sdns.baidu.com. 7200    IN      A       10.11.132.43
mail-in.sdns.baidu.com. 7200    IN      A       10.169.0.216

"""
#定义邮箱参数
# mail_sever = 'proxy-in.baidu.com'        #邮箱服务器地址
# mail_sever = 'mail1-in.baidu.com'        #邮箱服务器地址
# mail_sever = 'mail-in.sdns.baidu.com'        #邮箱服务器地址
# mail_sever = '10.169.43.11'        #邮箱服务器地址
# mail_sever = '10.11.132.43'        #邮箱服务器地址
mail_sever = '10.169.0.216'        #邮箱服务器地址

sender = 'v_baiguanghui@baidu.com'             #邮件发送方
reciver = 'v_maojunfang@baidu.com'             #邮件接收方

subject = 'hahaha'                 #邮件标题
content = 'hahaha'                   #邮件内容

#配置发送内容
msgroot = MIMEMultipart('related')
msgroot['Subject'] = Header(subject,'utf-8')
msgroot['To'] = reciver
msgroot['Cc'] = reciver
msgroot['From'] = sender

thebody = MIMEText(content,_subtype='plain',_charset='utf-8')
msgroot.attach(thebody)

asmtp = smtplib.SMTP()
asmtp.connect(mail_sever)
asmtp.sendmail(sender,reciver,msgroot.as_string())
asmtp.quit()
print('ok')
